package alg

import (
	"time"
)

// 判断两时间是否在同一周内
func IsSameWeek(t1, t2 time.Time, startDay ...int) bool {
	if len(startDay) == 0 {
		startDay = []int{1}
	}
	dt := 201600 + 86400*startDay[0]
	return ((t1.Unix() - int64(dt)) / 604800) == ((t2.Unix() - int64(dt)) / 604800)
}

func IsSameWeekMon(t1, t2 time.Time) bool {
	return ((t1.Unix() - 288000) / 604800) == ((t2.Unix() - 288000) / 604800)
}

func IsSameWeekSun(t1, t2 time.Time) bool {
	return ((t1.Unix() - 259200) / 604800) == ((t2.Unix() - 259200) / 604800)
}

// 获取一周的开始时间
func WeekStime1(t time.Time) time.Time {
	t = t.AddDate(0, 0, 1-int(t.Weekday()))
	return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, time.Local)
}

func WeekStime2(t time.Time) time.Time {
	if (t.Unix()-316800)/86400%7 == 0 {
		return time.Unix(t.Unix()/86400*86400, 0)
	}
	return time.Unix((t.Unix())/604800*604800+316800, 0)
}
